#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
const ll MOD = 1000;
/**
 * 快速幂
 * @param a
 * @param b
 * @return
 */
ll f(int a, int b) {
    if (b == 0 || a == 1)return 1;
    if (a == 0 || b == 1)return a % MOD;
    ll t = f(a, b >> 1);
    t = (t * t) % MOD;
    if (b & 1)t = a * t % MOD;
    return t;

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    for (int a, b; cin >> a >> b;) {
        if (a == 0 && b == 0)break;
        cout << f(a, b) << endl;
    }
    return 0;
}
